package hebClustering.vectorSpace.distances;

import hebClustering.vectorSpace.IVector;

/**
 * Implementation of the distance function Manhattan distance (AKA Taxi-cab geometry).
 * 
 *	@see <a href="http://en.wikipedia.org/wiki/Taxicab_geometry" target="_blank">Manhattan distance</a>
 */
public class ManhattanDistance implements IDistance{

	@Override
	public double calc(IVector v1, IVector v2) {
		double sum = 0;
		IVector diff = v1.sub(v2);
	
		for(int i : diff){
			sum += Math.abs(diff.ithValue(i));
		}
		
		return sum;
	}

}
